<?php
/*
Plugin Name: dKret RSS  widget
Description: Adds a sidebar widget to display RSS Links.
Author: J. Kretzschmar (based on RSS-Links widget of sandbox)
Version: 1.2
Author URI: http://diekretzschmars.de
*/

function widget_dkret_rsslinks($args) {
	extract($args);
	$options = get_option('widget_dkret_rsslinks');
	$title = empty($options['title']) ? __('RSS Links','dkret') : $options['title'];
		echo "\t\t\t$before_widget\n";
		echo "\t\t\t\t$before_title".$title.$after_title; ?>
				<ul>
<?php
	if (($options['posts'] == '0') || (!$options['posts'])) {
?>
					<li><a href="<?php bloginfo('rss2_url') ?>" title="<?php echo wp_specialchars(bloginfo('name'), 1) ?> <?php _e('Posts RSS feed', 'dkret'); ?>" rel="alternate" type="application/rss+xml"><?php _e('All posts', 'dkret') ?></a></li>
<?php
	}
?>
<?php
	if (($options['comments'] == '0') || (!$options['comments'])) {
?>
					<li><a href="<?php bloginfo('comments_rss2_url') ?>" title="<?php echo wp_specialchars(bloginfo('name'), 1) ?> <?php _e('Comments RSS feed', 'dkret'); ?>" rel="alternate" type="application/rss+xml"><?php _e('All comments', 'dkret') ?></a></li>
<?php 
	}
?>
				</ul>
	<?php echo "\n\t\t\t$after_widget";
}

// Admin section
function widget_control_dkret_rsslinks() {
 	$options = get_option('widget_dkret_rsslinks');
    		
	if ( $_POST['dkret-submit'] ) {

		if ( isset($_POST['dkret-rsslinks-title']) )
			$options['title'] = strip_tags(stripslashes($_POST['dkret-rsslinks-title']));
		if ( isset($_POST['dkret-rsslinks-posts']) )
			$options['posts'] = '1';
		else
			$options['posts'] = '0';
		if ( isset($_POST['dkret-rsslinks-comments']) )
			$options['comments'] = '1';
		else
			$options['comments'] = '0';

		update_option('widget_dkret_rsslinks', $options);
	}
	
	$title = htmlspecialchars($options['title'], ENT_QUOTES);
	
	// The Box content
?>
	<p>
		<label for="dkret-rsslinks-title" />
			<?php _e('Title:') ?> <input style="width: 200px;" id="dkret-rsslinks-title" name="dkret-rsslinks-title" type="text" value="<?php echo $title ?>" />
		</label>
	</p>
	<p>
		<label for="dkret-rsslinks-posts">
			<input id="dkret-rsslinks-posts" name="dkret-rsslinks-posts" type="checkbox" value="1" <?php checked('1', $options['posts']) ?>  />
			<?php _e('Hide Posts RSS feed', 'dkret') ?>
		</label>
		<br />
		<label for="dkret-rsslinks-comments">
			<input id="dkret-rsslinks-comments" name="dkret-rsslinks-comments" type="checkbox" value="1" <?php checked('1', $options['comments']) ?>  />
			<?php _e('Hide Comments RSS feed', 'dkret') ?>
		</label>
	</p>
	<input type="hidden" id="dkret-submit" name="dkret-submit" value="1" />
<?php
}

$widget_ops = array('classname' => 'widget_dkret_rsslinks', 'description' => __( "RSS links for posts and comments (dkret)", 'dkret') );
wp_register_sidebar_widget('rss-links', __('RSS Links','dkret'), 'widget_dkret_rsslinks', $widget_ops);
wp_register_widget_control('rss-links', __('RSS Links','dkret'), 'widget_control_dkret_rsslinks');
?>